home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Graphics Plus
/
Graphics Plus.iso
/
amiga
/
gui
/
prcgntn1.lha
/
Precognition
/
source
/
VScroller.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-23
|
11KB
|
400 lines
/* ==========================================================================
**
** VScroller.c
**
** ⌐1991 WILLISoft
**
** ==========================================================================
*/
#include <stdio.h>
#include "minmax.h"
#include "VScroller.h"
#include "VScrollerClass.h"
#include "EmbossedGadgetClass.h"
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include "amigamem.h"
void VScroller_SetInteractorWindow( VScroller *self, pcgWindow *window )
{
self->posr.IaWindow = window;
SetInteractorWindow( &self->vslider, window );
SetInteractorWindow( &self->uparrow, window );
SetInteractorWindow( &self->downarrow, window );
}
void VScroller_CleanUp( VScroller *self )
{
CleanUp( &self->vslider );
CleanUp( &self->uparrow );
CleanUp( &self->downarrow );
}
tPoint VScroller_SetLocation( VScroller *self,
PIXELS LeftEdge,
PIXELS TopEdge )
{
Point Up_size, Slider_size;
Point Up_pos, Down_pos;
Up_size = Size( &self->uparrow );
Slider_size = Size( &self->vslider );
SetLocation( &self->vslider, LeftEdge, TopEdge );
Up_pos.x = LeftEdge;
Up_pos.y = TopEdge + Slider_size.y;
SetLocation( &self->uparrow, Up_pos.x, Up_pos.y );
Down_pos.x = LeftEdge;
Down_pos.y = Up_pos.y + Up_size.y;
SetLocation( &self->downarrow, Down_pos.x, Down_pos.y );
self->posr.Location.x = LeftEdge;
self->posr.Location.y = TopEdge;
return Location( self );
}
tPoint VScroller_private_AskSize( VScroller *self,
PIXELS Width,
PIXELS Height,
Point *Up_size,
Point *Down_size,
Point *Slider_size )
{
Point size;
*Up_size = AskSize( &self->uparrow, 0, 0 );
*Down_size = AskSize( &self->downarrow, 0, 0 );
Slider_size->y = Height - (Up_size->y + Down_size->y);
Slider_size->x = MAX( Up_size->x, Down_size->x );
*Slider_size = AskSize( &self->vslider, Slider_size->x, Slider_size->y );
size.x = Slider_size->x;
size.y = Slider_size->y + Up_size->y + Down_size->y;
return size;
}
tPoint VScroller_AskSize( VScroller *self,
PIXELS Width,
PIXELS Height )
{
Point Up_size, Down_size, Slider_size, size;
size = VScroller_private_AskSize( self, Width, Height,
&Up_size, &Down_size, &Slider_size );
return size;
}
tPoint VScroller_SetSize( VScroller *self,
PIXELS Width,
PIXELS Height )
{
tPoint Up_size, Down_size, Slider_size, size;
tPoint pos;
size = VScroller_private_AskSize( self, Width, Height,
&Up_size, &Down_size, &Slider_size );
SetSize( &self->uparrow, Up_size.x, Up_size.y );
SetSize( &self->downarrow, Down_size.x, Down_size.y );
SetSize( &self->vslider, Slider_size.x, Slider_size.y );
/* Now must fix the positions of uparrow, down arrow. */
pos = Location( self );
SetLocation( self, pos.x, pos.y );
self->posr.Size = size;
AlignText( &self->vslider.eg.LabelText, Size(self) );
return size;
}
void VScroller_Render( VScroller *self, RastPort *RPort )
{
Render( &self->vslider, RPort );
Render( &self->uparrow, RPort );
Render( &self->downarrow, RPort );
}
Gadget *VScroller_FirstGadget( VScroller *self )
{
return FirstGadget( &self->vslider );
}
USHORT VScroller_nGadgets( VScroller *self )
{
return nGadgets( &self->vslider ) + nGadgets( &self->uparrow )
+ nGadgets( &self->downarrow );
}
ULONG VScroller_IDCMPFlags( VScroller *self )
{
return IDCMPFlags( &self->vslider )
| IDCMPFlags( &self->uparrow )
| IDCMPFlags( &self->downarrow );
}
USHORT VScroller_ClaimEvent( VScroller *self, IntuiMessage *event )
{
return ClaimEvent( &self->vslider, event )
| ClaimEvent( &self->uparrow, event )
| ClaimEvent( &self->downarrow, event );
}
BOOL VScroller_EnableIactor( VScroller *self, BOOL enable )
{
EnableIactor( &self->vslider, enable );
EnableIactor( &self->uparrow, enable );
EnableIactor( &self->downarrow, enable );
return enable;
}
USHORT VScroller_Respond( VScroller *self, IntuiMessage *event )
{
USHORT vsr = 0; /* Vertical slider response */
USHORT uar = 0; /* uparrow response */
USHORT dar = 0; /* down arrow response */
vsr = Respond( &self->vslider, event );
if (! (vsr & CONSUMED_EVENT))
{
/* Up Arrow */
uar = Respond( &self->uparrow, event );
if ((uar & CHANGED_STATE) && (Value(&self->uparrow)))
{
SlideLower( &self->vslider );
}
if (!(uar & CONSUMED_EVENT))
{
/* Down Arrow */
dar = Respond( &self->downarrow, event );
if ((dar & CHANGED_STATE) && (Value(&self->downarrow)))
{
SlideHigher( &self->vslider );
}
}
}
return vsr | uar | dar;
}
void VScroller_Refresh( VScroller *self )
{
pcgWindow *window;
if (window = InteractorWindow(self))
{
Refresh( &self->vslider );
Refresh( &self->uparrow );
Refresh( &self->downarrow );
}
}
USHORT VScroller_Value( VScroller *self )
{
return Value( &self->vslider );
}
USHORT VScroller_SetValue( VScroller *self, USHORT position )
{
return SetValue( &self->vslider, position );
}
USHORT VScroller_KnobSize( VScroller *self )
{
return KnobSize( &self->vslider );
}
USHORT VScroller_SetKnobSize( VScroller *self, USHORT knobsize )
{
return SetKnobSize( &self->vslider, knobsize );
}
char *VScroller_Title( VScroller *self )
{
return Title(&self->vslider);
}
BOOL VScroller_SetTitle( VScroller *self,
char *title )
{
SetTitle( &self->vslider, title );
AlignText( &self->vslider.eg.LabelText, Size(self) );
return TRUE;
}
AlignInfo VScroller_TextAlignment( VScroller *self )
{
return self->vslider.eg.LabelText.alignment;
}
AlignInfo VScroller_SetTextAlignment( VScroller *self,
UBYTE Flags,
BYTE Xpad,
BYTE Ypad )
{
self->vslider.eg.LabelText.alignment.Flags = Flags;
self->vslider.eg.LabelText.alignment.Xpad = Xpad;
self->vslider.eg.LabelText.alignment.Ypad = Ypad;
AlignText( &self->vslider.eg.LabelText, Size(self) );
return self->vslider.eg.LabelText.alignment;
}
#ifdef BUILDER
#include "BuilderMethods.h"
#include "GraphicObject_Builder.h"
#include "Positioner_Builder.h"
#include "Positioner_coder.h"
struct BuilderMethods VScroller_bm;
VScroller *VScroller_New( VScroller *self )
{
VScroller *new_vscroller = NULL;
if (new_vscroller = (VScroller *) Amalloc(sizeof(VScroller)))
{
VScroller_Init( new_vscroller, self->posr.Location.x, self->posr.Location.y,
self->posr.Size.y, self->Pens,
Title(self) );
GiveItAName( new_vscroller );
}
return new_vscroller;
}
#endif
BOOL VScroller_elaborated = FALSE;
struct PositionerClass VScroller_Class;
void VScrollerClass_Init( struct PositionerClass *class )
{
PositionerClass_Init( class );
class->isa = PositionerClass();
class->ClassName = "VScroller";
/* class->New = VScroller_New;*/
class->CleanUp = VScroller_CleanUp;
class->SetLocation = VScroller_SetLocation;
class->AskSize = VScroller_AskSize;
class->SetSize = VScroller_SetSize;
class->SizeFlags = GraphicObject_SizeFlagsY;
class->Render = VScroller_Render;
class->SetInteractorWindow = VScroller_SetInteractorWindow;
class->FirstGadget = VScroller_FirstGadget;
class->nGadgets = VScroller_nGadgets;
class->IDCMPFlags = VScroller_IDCMPFlags;
class->ClaimEvent = VScroller_ClaimEvent;
class->Respond = VScroller_Respond;
class->Refresh = VScroller_Refresh;
class->EnableIactor = VScroller_EnableIactor;
class->isEnabled = EmbossedGadget_isEnabled;
class->Activate = NULL;
class->isActive = NULL;
class->SetKnobSize = VScroller_SetKnobSize;
class->SetValue = VScroller_SetValue;
class->KnobSize = VScroller_KnobSize;
class->Value = VScroller_Value;
class->Title = VScroller_Title;
class->SetTitle = VScroller_SetTitle;
class->TextAlignment = VScroller_TextAlignment;
class->SetTextAlignment = VScroller_SetTextAlignment;
#ifdef BUILDER
go_InitBuilderMethods( &VScroller_bm );
VScroller_bm.New = VScroller_New;
VScroller_bm.PropEdit = Positioner_PropEdit;
VScroller_bm.WriteCode = Positioner_WriteCode;
class->BuilderMethods = &VScroller_bm;
#endif
}
struct PositionerClass *VScrollerClass( void )
{
if (! VScroller_elaborated)
{
VScrollerClass_Init( &VScroller_Class );
VScroller_elaborated = TRUE;
}
return &VScroller_Class;
}
void VScroller_Init( VScroller *self,
PIXELS LeftEdge,
PIXELS TopEdge,
PIXELS Height,
pcg_3DPens Pens,
char *label )
{
Gadget *g;
Positioner_Init(self);
self->posr.isa = VScrollerClass();
self->posr.Next = NULL;
self->posr.PObjectName = NULL;
self->posr.Location.x = LeftEdge;
self->posr.Location.y = TopEdge;
self->Pens = Pens;
/*
** Initialize objects with dumb values, just so that they are now
** proper objects.
*/
ArrowGadget_Init( &self->uparrow, LeftEdge, TopEdge,
UpArrow, Pens );
ArrowGadget_Init( &self->downarrow, LeftEdge, TopEdge,
DownArrow, Pens );
VSlider_Init( &self->vslider, LeftEdge, TopEdge, 0, 0, Pens, NULL );
self->vslider.eg.Next = &self->uparrow;
self->uparrow.Next = &self->downarrow;
SetSize( self, 0, Height );
SetTitle( self, label );
SetTextAlignment( self, tx_XCENTER | tx_BOTTOM | tx_OUTSIDE, STD_XPAD, STD_YPAD );
/* Chain the gadgets together. */
g = FirstGadget( self );
ChainGadgets( g, FirstGadget( &self->uparrow ) );
ChainGadgets( g, FirstGadget( &self->downarrow ) );
}